package com.example.liang.basamovie.json;

import android.util.Log;

import com.example.liang.basamovie.bean.FindComment;
import com.example.liang.basamovie.bean.FindPlayerInfoBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hudongwx on 17-2-17.
 */
public class FindPlayerInfo {

    public static FindPlayerInfoBean getPlayerInfo(String path){
        try {
            JSONObject object = new JSONObject(path);
            FindPlayerInfoBean playerInfoBean = new FindPlayerInfoBean();
            if(object.has("wantToWatchCount")){
                playerInfoBean.setWantWatchConut(object.optInt("wantToWatchCount"));
            }
            if(object.has("watchedsCount")){
                playerInfoBean.setWatchedsCount(object.optInt("watchedsCount"));
            }
            if(object.has("topicsCount")){
                playerInfoBean.setTopicsCount(object.optInt("topicsCount"));
            }
            JSONObject userInfo = object.getJSONObject("userInfo");
            playerInfoBean.setName(userInfo.optString("nickname"));
            if(userInfo.has("headImgMinUrl")){
                playerInfoBean.setImageUrl(userInfo.optString("headImgMinUrl"));
            }
            JSONArray array = object.getJSONArray("feedsList");
            List<FindComment> list=new ArrayList();
            for (int i = 0; i <array.length() ; i++) {
                JSONObject jsonObject = array.getJSONObject(i);
                FindComment findComment = new FindComment();
                findComment.setContent(jsonObject.optString("filmRecommendsRecommend"));
                findComment.setTitle(jsonObject.optString("articleName"));
                list.add(findComment);
            }
            playerInfoBean.setList(list);
            //Log.e("sss",list.size()+"--------");
            return playerInfoBean;


        } catch (JSONException e) {
            e.printStackTrace();
        }
        Log.e("message","演员信息解析出错");
        return new FindPlayerInfoBean();
    }
}
